﻿using Prism.Events;
using RoboAssembleX.Application.AddBoard1;
using RoboAssembleX.Application.AddBoard2;
using RoboAssembleX.Application.AddGlass;
using RoboAssembleX.Application.AddGlass1;
using RoboAssembleX.Application.AddNeedle2;
using RoboAssembleX.Application.Common;
using RoboAssembleX.Application.Robot;
using RoboAssembleX.Application.Vision;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RoboAssembleX.Application.ActionJobs
{
    public class ActionJob52 : BindableBase, IActionJob
    {
        private string name = "基片2推模"; public string Name { get => name; }
        private bool running; public bool Running { get => running; set { running = value; RaisePropertyChanged(); } }
        private bool enable = true; public bool Enable { get => enable; set { enable = value; RaisePropertyChanged(); } }
        private int priority = 0;
        private readonly IEventAggregator eventAggregator;
        private readonly AddBoard2Service addBoard2Service;
        private readonly AddBoard2Model addBoard2Model;
        private readonly VisionService visionService;

        public ActionJob52(IEventAggregator eventAggregator, AddBoard2Service addBoard2Service, AddBoard2Model addBoard2Model, VisionService visionService)
        {
            this.eventAggregator = eventAggregator;
            this.addBoard2Service = addBoard2Service;
            this.addBoard2Model = addBoard2Model;
            this.visionService = visionService;
        }

        public int Priority { get => priority; set { priority = value; RaisePropertyChanged(); } }

        public bool IsReady
        {
            get
            {
                // 引线允许取料  引线料位有料
                return  addBoard2Model.AllowPut && addBoard2Model.InPosUsed
                     && !addBoard2Model.OutPosUsed;
            }
        }

        public async Task RunActionAsync()
        {
            Running = true;
            await visionService.SendVisionCmdAsync("p1");
            await Task.Delay(1000);
            eventAggregator.GetEvent<MessageEvent>().Publish(new MessageEventArgs("启动基片2推模!", 1));
            addBoard2Service.Action();
            await Task.Delay(500);
            Running = false;
        }
    }
}
